package org.example.completed.controller;

import org.example.completed.domain.Pets;
import org.example.completed.domain.Product;
import org.example.completed.model.vo.ResultVO;
import org.example.completed.service.PetService;
import org.example.completed.utils.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * pet宠物
 *
 * @since 2025-04-15
 */
@RestController
@RequestMapping("/pet")
public class PetController {
    @Autowired
    private PetService petService;

    /**
     * 获取所有宠物
     * @return
     */
    @GetMapping("/list")
    public ResultVO<List<Pets>> list() {
        List<Pets> petsList = petService.list();
        return ResultVO.ok(petsList);
    }

    /**
     * 新增宠物记录
     * @param pets 宠物实体
     * @return 操作结果
     */
    @PostMapping("/add")
    public ResultVO<Boolean> add(@RequestBody Pets pets) {
        boolean saveResult = petService.save(pets);
        return saveResult ? ResultVO.ok() : ResultVO.fail(500, "新增失败");
    }

    /**
     * 删除宠物记录
     * @param id 宠物记录ID
     * @return 操作结果
     */
    @PostMapping("/delete/{id}")
    public ResultVO<Boolean> delete(@PathVariable String id) {
        boolean removeResult = petService.removeById(id);
        return removeResult ? ResultVO.ok() : ResultVO.fail(500, "删除失败");
    }

    /**
     * 修改宠物记录
     * @param pets 宠物实体
     * @return 操作结果
     */
    @PostMapping("/update")
    public ResultVO<Boolean> update(@RequestBody Pets pets) {
        boolean updateResult = petService.updateById(pets);
        return updateResult ? ResultVO.ok() : ResultVO.fail(500, "修改失败");
    }

    /**
     * 根据 ID 查询宠物
     * @param id 产品 ID
     * @return 产品实体
     */
    @GetMapping("/select/{id}")
    public ResultVO<Pets> selectById(@PathVariable String id) {
        Pets byId = petService.getById(id);
        return ResultVO.ok(byId);
    }

}
